package com.okyai.cms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.okyai.common.annotation.Log;
import com.okyai.common.enums.BusinessType;
import com.okyai.cms.domain.CmsApp;
import com.okyai.cms.service.ICmsAppService;
import com.okyai.common.core.controller.BaseController;
import com.okyai.common.core.domain.AjaxResult;
import com.okyai.common.utils.poi.ExcelUtil;
import com.okyai.common.core.page.TableDataInfo;

/**
 * 网站管理Controller
 * 
 * @author okyai
 * @date 2020-12-03
 */
@Controller
@RequestMapping("/cms/app")
public class CmsAppController extends BaseController
{
    private String prefix = "cms/app";

    @Autowired
    private ICmsAppService cmsAppService;

    @RequiresPermissions("cms:app:view")
    @GetMapping()
    public String app()
    {
        return prefix + "/app";
    }

    /**
     * 查询网站管理列表
     */
    @RequiresPermissions("cms:app:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsApp cmsApp)
    {
        startPage();
        List<CmsApp> list = cmsAppService.selectCmsAppList(cmsApp);
        return getDataTable(list);
    }

    /**
     * 导出网站管理列表
     */
    @RequiresPermissions("cms:app:export")
    @Log(title = "网站管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsApp cmsApp)
    {
        List<CmsApp> list = cmsAppService.selectCmsAppList(cmsApp);
        ExcelUtil<CmsApp> util = new ExcelUtil<CmsApp>(CmsApp.class);
        return util.exportExcel(list, "app");
    }

    /**
     * 新增网站管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存网站管理
     */
    @RequiresPermissions("cms:app:add")
    @Log(title = "网站管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsApp cmsApp)
    {
        return toAjax(cmsAppService.insertCmsApp(cmsApp));
    }

    /**
     * 修改网站管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsApp cmsApp = cmsAppService.selectCmsAppById(id);
        mmap.put("cmsApp", cmsApp);
        return prefix + "/edit";
    }

    /**
     * 修改保存网站管理
     */
    @RequiresPermissions("cms:app:edit")
    @Log(title = "网站管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsApp cmsApp)
    {
        return toAjax(cmsAppService.updateCmsApp(cmsApp));
    }

    /**
     * 删除网站管理
     */
    @RequiresPermissions("cms:app:remove")
    @Log(title = "网站管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsAppService.deleteCmsAppByIds(ids));
    }
}
